#include "StdAfx.h"
#include "DataOutput.h"

DataOutput::DataOutput(void)
{

#ifdef WINCE
	FileName =  "\\Removable Storage\\heater.csv";
#else
	FileName =  "\\heater.csv";
#endif

	if ((stream = fopen( FileName, "a+" )) == 0 )
	{
		//TODO bearbeiten fehler
	}

}

DataOutput::~DataOutput(void)
{
	fclose( stream );
}

bool DataOutput::write(float temp)
{
	static float oldTemp = 0;
	static DWORD oldMinute = 0;
	SYSTEMTIME st;

	GetLocalTime(&st);              // gets current time

	if(fabs(oldTemp - temp) >= 1.0f)
	{
		fprintf( stream, "%d/%d/%d;%d:%d:%d;%f\n", 
			st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, temp);

		oldTemp = temp;

		if(!fflush(stream))
			{
				//TODO bearbeiten fehler
			}
		
	}
/*
		if(labs(oldMinute - st.wMinute) > 1)
		{
			if(!fflush(stream))
			{
				//TODO bearbeiten fehler
			}
			oldMinute = st.wMinute;
		}
*/


	return true;
}
